package com.atguigu.juc.day03.jmm;

import java.util.concurrent.atomic.AtomicInteger;

public class Demo06CAS {

    public static void main(String[] args) {

        // 1、创建原子类对象
        AtomicInteger number = new AtomicInteger(10);

        // 2、修改原子类的数值
        int expect = 10;
        int update = 20;

        number.compareAndSet(expect, update);

        // 3、获取原子类现在的数值
        int intNumber = number.intValue();
        System.out.println("intNumber = " + intNumber);

        expect = 10;
        update = 25;
        number.compareAndSet(expect, update);

        intNumber = number.intValue();
        System.out.println("intNumber = " + intNumber);

    }

}
